package shuangzhizhen

import (
	"math"
	"sort"
)

func removeElement(nums []int, val int) int {
	return -1
}

// 简单版本，比较然后换最大值

func RemoveE(nums []int, val int) int {
	a := math.MaxInt32
	ans := 0
	for i, v := range nums {
		if v == val {
			nums[i] = a
		} else {
			ans++
		}
	}
	sort.Ints(nums)
	return ans
}

func RemoveE1(nums []int, val int) int {
	slow, fast := 0, 0
	n := len(nums)
	for fast < n {
		if nums[fast] != val {
			nums[slow] = nums[fast]
			fast++
			slow++
		} else {
			fast++
		}
	}
	return slow
}
